from django.shortcuts import render,get_object_or_404,redirect
from django.http import HttpResponse,HttpResponseRedirect
from django.template import loader
from django.http import Http404
from django.urls import reverse
from .models import Entry

# Create your views here.

def entry(request,num=1):
    entryObject=Entry.objects.get(id=num)
    return redirect(entryObject)  #redirect可以接收一个model 实例，会自动调用实例的 get_absolute_url() 方法
    #除了接收一个 model对象，还可以接收 反向解析url；硬编码url；完整url
    #return redirect(reverse("blog:oldsiteentry",args=(num,))) #反向解析url
    #return redirect("/blog/oldsite/%d/" %num)                 #硬编码url
    #return redirect("http://www.baidu.com/")                  #完整url

def oldsiteentry(request,num=1):
    return HttpResponse("this is %d ,rediected!" %num) #这是1 的重定向结果